unit Unit22;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBCtrls, StdCtrls, unit2, ExtCtrls;

type
  TForm22 = class(TForm)
    Label1: TLabel;
    DBLookupComboBox1: TDBLookupComboBox;
    Label2: TLabel;
    ComboBox1: TComboBox;
    RadioGroup19: TRadioGroup;
    Label3: TLabel;
    Button1: TButton;
    Button2: TButton;
    ListBox1: TListBox;
    Label4: TLabel;
    ListBox2: TListBox;
    Button3: TButton;
    Button4: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ComboBox1Select(Sender: TObject);
    procedure DBLookupComboBox1CloseUp(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure ListBox2KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Button1Click(Sender: TObject);
    procedure RadioGroup19Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form22: TForm22;

implementation

uses unit15;

{$R *.dfm}

procedure TForm22.FormCreate(Sender: TObject);
begin
ComboBox1.Items.Add('1');
ComboBox1.Items.Add('2');
ComboBox1.Items.Add('3');
ComboBox1.Items.Add('4');
ComboBox1.Items.Add('5');
ComboBox1.Items.Add('6');
ComboBox1.ItemIndex:=0;
end;

procedure TForm22.Button2Click(Sender: TObject);
begin
ListBox2.Clear;
Form22.Close;
end;

procedure TForm22.ComboBox1Select(Sender: TObject);
var
i:integer;
begin
if DBLookupComboBox1.Text<>'' then
begin
ListBox1.Clear;
datamodule2.QueryRasp.SQL.Clear;
datamodule2.QueryRasp.SQL.Text:='SELECT P.Name FROM Groups P, Kafedry P1 WHERE P1.Name='#39+DBLookupComboBox1.Text+#39' AND P.ID_Kafedry=P1.ID AND P.Kurs='#39+ComboBox1.Text+#39' AND P.Osen='#39+IntToStr(RadioGroup19.ItemIndex)+#39'';
datamodule2.QueryRasp.Open;
for i:=1 to datamodule2.SourceRasp.DataSet.RecordCount do
 begin
 ListBox1.Items.Add(datamodule2.SourceRasp.DataSet.fieldbyname('Name').AsString);
 datamodule2.SourceRasp.DataSet.Next;
 end;
datamodule2.QueryRasp.Close;
end;
end;

procedure TForm22.DBLookupComboBox1CloseUp(Sender: TObject);
var
i:integer;
begin
ListBox1.Clear;
datamodule2.QueryRasp.SQL.Clear;
datamodule2.QueryRasp.SQL.Text:='SELECT P.Name FROM Groups P, Kafedry P1 WHERE P1.Name='#39+DBLookupComboBox1.Text+#39' AND P.ID_Kafedry=P1.ID AND P.Kurs='#39+ComboBox1.Text+#39' AND P.Osen='#39+IntToStr(RadioGroup19.ItemIndex)+#39'';
datamodule2.QueryRasp.Open;
for i:=1 to datamodule2.SourceRasp.DataSet.RecordCount do
 begin
 ListBox1.Items.Add(datamodule2.SourceRasp.DataSet.fieldbyname('Name').AsString);
 datamodule2.SourceRasp.DataSet.Next;
 end;
datamodule2.QueryRasp.Close;
end;

procedure TForm22.Button3Click(Sender: TObject);
var
i,j,k:integer;
begin
for i:=0 to listbox1.Items.Count-1 do
 if listbox1.Selected[i] then
 begin
 k:=0;
  for j:=0 to listbox2.Items.Count-1 do
  if listbox2.Items.Strings[j]=listbox1.Items.Strings[i] then inc(k);
  if k=0 then listbox2.Items.Add(listbox1.Items.Strings[i]);
 end;
end;

procedure TForm22.Button4Click(Sender: TObject);
var i,j,k:integer;
begin
 for i:=0 to listbox1.Items.Count-1 do
  begin
  k:=0;
  for j:=0 to listbox2.items.Count-1 do
  if listbox2.Items.Strings[j]=listbox1.Items.Strings[i] then
  inc(k);
  if k=0 then
  listbox2.Items.Add(listbox1.Items.Strings[i]);
 end;
end;

procedure TForm22.ListBox2KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key=vk_delete then
 ListBox2.Items.Delete(ListBox2.ItemIndex);
end;

procedure TForm22.Button1Click(Sender: TObject);
var
i,j,k:integer;
begin
if ListBox2.Items.Count<>0 then
 begin
 for i:=0 to listbox2.Items.Count-1 do
  begin
  k:=0;
  for j:=0 to Unit15.Form15.ListBox1.items.Count-1 do
  if Unit15.Form15.ListBox1.Items.Strings[j]=listbox2.Items.Strings[i] then
  inc(k);
  if k=0 then
  Unit15.Form15.ListBox1.Items.Add(listbox2.Items.Strings[i]);
 end;
 ListBox2.Clear;
 Form22.Close;
 end;
end;

procedure TForm22.RadioGroup19Click(Sender: TObject);
var
i:integer;
begin
if DBLookupComboBox1.Text<>'' then
begin
ListBox1.Clear;
datamodule2.QueryRasp.SQL.Clear;
datamodule2.QueryRasp.SQL.Text:='SELECT P.Name FROM Groups P, Kafedry P1 WHERE P1.Name='#39+DBLookupComboBox1.Text+#39' AND P.ID_Kafedry=P1.ID AND P.Kurs='#39+ComboBox1.Text+#39' AND P.Osen='#39+IntToStr(RadioGroup19.ItemIndex)+#39'';
datamodule2.QueryRasp.Open;
for i:=1 to datamodule2.SourceRasp.DataSet.RecordCount do
 begin
 ListBox1.Items.Add(datamodule2.SourceRasp.DataSet.fieldbyname('Name').AsString);
 datamodule2.SourceRasp.DataSet.Next;
 end;
datamodule2.QueryRasp.Close;
end;
end;

end.
